package com.hoshiicloud.user.param.rbac;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hoshiicloud.common.query.PageParam;
import com.hoshiicloud.rbac.entity.SysUsers;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * <p>
 * 查询用户参数
 * </p>
 *
 * @author Mr.Wu
 * @since 2019-04-27
 */
@Data
public class SysUsersQueryParam extends PageParam implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * ID
	 */
	@ApiModelProperty(value = "ID")
	private Long id;

	/**
	 * 组织id
	 */
	@ApiModelProperty(value = "组织id")
	private Long deptId;

	/**
	 * 帐号
	 */
	@ApiModelProperty(value = "帐号")
	private String username;

	/**
	 * 姓名
	 */
	@ApiModelProperty(value = "姓名")
	private String realname;

	/**
	 * 头像
	 */
	@ApiModelProperty(value = "头像")
	private String avatar;

	/**
	 * 电话
	 */
	@ApiModelProperty(value = "电话")
	private String phone;

	/**
	 * 邮箱
	 */
	@ApiModelProperty(value = "邮箱")
	private String email;

	/**
	 * 性别
	 */
	@ApiModelProperty(value = "性别")
	private Integer sex;

	/**
	 * 状态(0:正常,1:锁定)
	 */
	@ApiModelProperty(value = "状态(0:正常,1:锁定)")
	private Integer locked;

	/**
	 * 角色名称
	 */
	@ApiModelProperty(value = "角色名称")
	private String roleName;

	public QueryWrapper<SysUsers> convertToQueryWrapper() {
		QueryWrapper<SysUsers> queryWrapper = new QueryWrapper<SysUsers>();
		queryWrapper.eq(this.id != null, "id", this.id);
		queryWrapper.eq(this.deptId != null, "dept_id", this.deptId);
		queryWrapper.eq(StringUtils.isNotBlank(this.username), "username", this.username);
		queryWrapper.eq(StringUtils.isNotBlank(this.realname), "real_name", this.realname);
		queryWrapper.eq(StringUtils.isNotBlank(this.avatar), "avatar", this.avatar);
		queryWrapper.eq(StringUtils.isNotBlank(this.phone), "phone", this.phone);
		queryWrapper.eq(StringUtils.isNotBlank(this.email), "email", this.email);
		queryWrapper.eq(this.sex != null, "sex", this.sex);
		queryWrapper.eq(this.locked != null, "locked", this.locked);

		return queryWrapper;
	}
}
